import csv
import getpath
import os
import openpyxl
from openpyxl import load_workbook
import myglobal
import config_json
import sample
import logging
def getDataObjects(fname):
    xlBook = load_workbook(filename=fname)
    table = xlBook.worksheets[0]
    logging.info(dir(table))
    create_table = False
    data = []
    for row in table.values:
        r = []
        for one in row:
            if one is not None:
                r.append(one)
            else:
                r.append(None)
        data.append(r)
    samples = []
    at = 0
    while True:
        s=sample.Sample()#ample = {"items": [], "conc": []}
        try:
            sampleid = data[at + 1][0]
            # sample["sampleid"] = sampleid
            s.sampleid=sampleid
            s.num=at
            logging.info(sampleid)
        except IndexError:
            break
        col = 1
        while True:
            try:
                # logging.info(at+2,col)
                item = data[at + 2][col]
                conc = data[at + 3][col]
                # should replace blank to other char
                # sample["items"].append((item, ""))  # .append(item + "_")
                conc=myglobal.myfloat(conc)
                s.items[(item,"")]=conc# sample["conc"].append(conc)
                # sample["mass"] = ""
                # sample["volume"] = ""
                # self.addCalcColumn(sample)
            except IndexError:
                break
            if (item == ""):
                break
            col += 1
        if sampleid == "":
            break
        samples.append(s)
        at += 7
    return(samples)
def getdata_std(fname):
    data0=getdata_raw(fname)
    data=zl_data_std(data0)
    return data
def getdata0():
    fname=os.path.join(getpath.getpath(),"..","data","spec","spec","82829.XLSX")
    data=getDataObjects(fname)
    return data
def getdata_std0():
    fname=os.path.join(getpath.getpath(),"..","data","spec","4460","biaoyangceshi4460.XLSX")
    data=getdata_std(fname)
    return data
if __name__=="__main__":
    # data=getdata_std0()
    data=getdata0()
    print(data)
    print(data[0],data[0].items)
    print(data[1])
    print(data[2])
    print(data[-1])